<template>
	<view>
		<!-- 安卓购买套餐强 -->
		<u-popup round="8" :show="show" @close="closeFn" mode="center">
			<view class="rewBuyPop">
				<view class="close" @click="closeFn">
					<u-icon name="close-circle" color="#fff" size="32"></u-icon>
				</view>
				<view class="top">
					<view class="imgcont">
						<image :src="taocanimages" mode="widthFix" class="img"></image>
					</view>
					<view class="cloum-cont">
						<view class="cloum" v-for="(item,index) in taocanList" :key="index" @click="handleRenew(item)">
							<image v-if="item.tuijian==1" class="package-img" src="/static/img/package-bg.jpg"
								mode="widthFix"></image>
							<image v-else-if="item.tuijian==2" class="package-img" src="/static/img/packageo.png"
								mode="widthFix"></image>
							<image class="tuijian-icon" v-if="item.tuijian==2" src="/static/img/packager.png"
								mode="widthFix"></image>
							<view class="package-info">
								<view class="package-detail">
									<view class="package-price">
										<text>￥</text>
										{{item.price}}
									</view>
									<view class="originalprice">
										<view>限时优惠</view>
										<text>{{item.originalprice}}</text>
									</view>
									<view class="package-name">{{item.name}}</view>
								</view>
								<view class="package-buy" :class="{'title-o':item.tuijian==2}">立即抢购</view>
								<!-- <view class="left">
									{{item.name}}
								</view>
								<view class="right">
									<view class="price">
										￥{{item.price}}
									</view>
									<view class="yuan">
										￥{{item.originalprice}}
									</view>
								</view> -->
							</view>
						</view>
					</view>
				</view>


				<!-- <view class="footer-btn btncenter">

					<view class="btn" @click="closeFn">
						关闭
					</view>
				</view> -->
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		name: "andrtaocan",
		props: ['show', 'taocanid'],
		data() {
			return {
				taocanimages: '',
				taocanList: [],
			};
		},
		mounted() {
			console.log(this.taocanid, 9999)
			this.getInfo()
			this.getImg()
		},

		methods: {
			closeFn() {
				this.$emit('close')
			},
			getInfo() {
				this.$req.post('/web/vippackagelist', {
					id: this.taocanid,
					uid: uni.getStorageSync('uid')
				}).then((res) => {
					let info = res.data.data
					this.taocanList = info
				})
			},
			getImg() {
				this.$req.post('/web/vippackageimage', {
					id: this.taocanid,

				}).then((res) => {
					this.taocanimages = res.data.data
				})
			},
			handleRenew(row) {
				let req = {
					uid: uni.getStorageSync('uid'),
					vippackageid: row.id
				}
				uni.showLoading({

				})
				this.$req.post('/shanghu/wechatpay', req).then((res) => {
					uni.hideLoading()
					let data = res.data
					if (data.code === 0) {
						let paydata = data.data
						this.pay(paydata)
					} else {
						wx.showToast({
							mask: true,
							icon: 'none',
							title: data,
							msg
						})
					}
				})
			},
			pay(paydata) {
				var that  =this;
				wx.requestPayment({
					nonceStr: paydata.nonceStr, // 随机字符串
					package: paydata.package, // 固定值
					signType: paydata.signType, // 统一下单订单号 
					timeStamp: paydata.timeStamp, // 时间戳（单位：秒）
					paySign: paydata.sign, // 签名，这里用的 MD5/RSA 签名
					success(res) {
						wx.showToast({
							mask: true,

							title: '购买成功',

						})
						that.$emit('close')
						that.$emit('refsh')
					},
					fail(e) {
						wx.showToast({
							mask: true,
							icon: '支付失败',
							title: data,
							msg
						})

						console.log(e, 8888)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.rewBuyPop {
		width: 90vw;
		display: flex;
		flex-direction: column;
		// align-items: center;
		padding: 0 0 30rpx 0;
		height: 90vh;
		overflow: hidden;
		position: relative;

		.close {
			position: absolute;
			right: 20rpx;
			top: 20rpx;
			z-index: 2;
		}

		.top {
			flex: 1;
			overflow-y: auto;
			border-radius: 8px 8px 0 0;

			.imgcont {
				overflow: hidden;
				width: 100%;



				.img {
					display: block;
					width: 100%;
					height: 100%;
				}
			}



			.name {
				font-size: 28rpx;
				margin-top: 30rpx;
				flex: 1;
				padding: 0 20rpx;
			}

			.cloum-cont {
				margin-top: 40rpx;
				padding: 0 24rpx;

				.cloum {
					display: flex;
					justify-content: space-between;
					border-radius: 8rpx;
					margin-bottom: 40rpx;
					// overflow: hidden;
					position: relative;
					align-items: center;

					.package-img {
						position: relative;
						z-index: 1;
						width: 100%;
					}

					.package-info {
						width: 100%;
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						padding: 0 20rpx;
						font-size: 28rpx;
						position: absolute;
						left: 0;
						z-index: 2;
						color: #fff;
						align-items: center;
					}

					.tuijian-icon {
						position: absolute;
						right: 20rpx;
						z-index: 4;
						width: 70rpx;
						height: 70rpx;
						top: -26rpx;
					}

					.package-detail {
						display: flex;
						flex-direction: row;
						justify-content: flex-start;
						align-items: center;
					}

					.package-price {
						font-size: 40rpx;
						font-weight: bold;

						text {
							font-size: 24rpx;
							margin-right: 4rpx;
						}
					}

					.originalprice {
						margin-left: 20rpx;
						font-size: 22rpx;

						text {
							font-weight: bold;
							text-decoration: line-through;
						}
					}

					.package-name {
						font-size: 32rpx;
						margin-left: 20rpx;
					}

					.package-buy {
						color: #44c78d;
						font-size: 28rpx;
						margin-right: 36rpx;
					}

					.title-o {
						color: #ff9d5c
					}

					.left {}

					.right {
						display: flex;
						align-items: center;

						.price {
							color: #fa3534;
						}

						.yuan {
							padding-left: 10rpx;
							color: #999;
							text-decoration: line-through;
						}
					}
				}
			}

		}

		.footer-btn {
			padding-left: 24rpx;
			padding-right: 24rpx;
			flex-shrink: 0;
			padding-top: 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 100%;

			.btn {
				line-height: 35rpx;
				width: calc(50% - 15rpx);
				padding: 20rpx;
				border-radius: 8rpx;
				font-size: 30rpx;
				font-weight: 500;
				text-align: center;
				background-color: #f5f5f5;
			}

			.confirmbtn {
				background-color: #57bd6a;
				color: #fff;
			}
		}

		.btncenter {
			justify-content: center;
		}
	}
</style>